#!/bin/bash
yum update -y \
&& echo "yum update finished!" \
&& yum -y install texinfo \
&& echo "texinfo install finished!" \
&& mkdir -p /home/environment/jdk \
&& cd /home/environment/jdk \
&& wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz \
&& tar -zxvf jdk-17_linux-x64_bin.tar.gz \
&& echo "JAVA_HOME=/home/environment/jdk/jdk-17.0.7" >>/etc/profile \
&& echo "CLASSPATH=.:\${JAVA_HOME}/lib" >>/etc/profile \
&& echo "PATH=\${JAVA_HOME}/bin:\$PATH" >>/etc/profile \
&& echo "export CLASSPATH PATH" >>/etc/profile \
&& source /etc/profile \
&& echo "jdk17 install finished!" \
&& yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo \
&& yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y \
&& echo "docker install finished!" \
&& systemctl start docker \
&& systemctl enable docker.service \
&& echo "docker enable boot/startup finished!" \
&& mkdir -p /home/environment/mysql/config \
/home/environment/mysql/data \
/home/environment/mysql/log \
&& touch /home/environment/mysql/config/my.cnf \
&& chmod -R 777 /home/environment/mysql \
&& docker pull mysql:8.0.33 \
&& docker run \
--name mysql \
-d \
-p 3306:3306 \
--restart=always \
-v /home/environment/mysql/log:/var/log/mysql \
-v /home/environment/mysql/data:/var/lib/mysql \
-v /home/environment/mysql/config:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=YuZhenAn123. \
mysql:8.0.33 \
&& echo "mysql8.0.33 start!" \
&& mkdir -p /home/environment/redis/config \
/home/environment/redis/data \
&& cd /home/environment/redis \
&& wget http://download.redis.io/releases/redis-7.0.1.tar.gz \
&& tar -zxvf redis-7.0.1.tar.gz \
&& cp /home/environment/redis/redis-7.0.1/redis.conf /home/environment/redis/config/redis.conf \
&& chmod -R 777 /home/environment/redis \
&& sed -i 's/protected-mode yes/protected-mode no/' /home/environment/redis/config/redis.conf \
&& sed -i 's/bind 127.0.0.1 -::1/bind 0.0.0.0/' /home/environment/redis/config/redis.conf \
&& echo "requirepass YuZhenAn123." >>/home/environment/redis/config/redis.conf \
&& docker pull redis:7.0.11 \
&& docker run --name redis-node1 \
-d \
--restart=always \
-p 6379:6379 \
-v /home/environment/redis/data:/data \
-v /home/environment/redis/config/redis.conf:/etc/redis/redis.conf \
redis:7.0.11 \
redis-server /etc/redis/redis.conf \
&& echo "redis7.0.11 start!" \
&& mkdir -p /home/environment/nginx/conf \
/home/environment/nginx/html \
/home/environment/nginx/logs \
&& docker pull nginx:1.24.0 \
&& docker run --name nginx -p 80:80 -d nginx:1.24.0 \
&& docker cp nginx:/etc/nginx/nginx.conf /home/environment/nginx/conf/nginx.conf \
&& docker cp nginx:/etc/nginx/conf.d /home/environment/nginx/conf/ \
&& docker cp nginx:/usr/share/nginx/html /home/environment/nginx/ \
&& chmod -R 777 /home/environment/nginx \
&& docker stop nginx \
&& docker rm nginx \
&& docker run -p 80:80 --name nginx --restart=always -d \
-v /home/environment/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/environment/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/environment/nginx/html:/usr/share/nginx/html \
-v /home/environment/nginx/logs:/var/log/nginx \
nginx:1.24.0 \
&& echo "nginx1.24.0 start!" \
&& mkdir -p /home/environment/minio/config \
/home/environment/minio/data \
&& chmod -R 777 /home/environment/minio \
&& docker pull minio/minio:latest \
&& docker run \
--name minio \
-d \
--restart=always \
-p 9000:9000 \
-p 9090:9090 \
-v /home/environment/minio/data:/data \
-v /home/environment/minio/config:/root/.minio \
-e MINIO_ROOT_USER=root \
-e MINIO_ROOT_PASSWORD=YuZhenAn123. \
minio/minio server /data --console-address ":9090" \
&& echo "minio start!" \
&& mkdir -p /home/environment/rabbitmq/config \
/home/environment/rabbitmq/data \
/home/environment/rabbitmq/log \
&& docker pull rabbitmq:3.12.1 \
&& docker run \
-d \
--hostname myRabbitmq \
--name rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:3.12.1 \
&& docker cp rabbitmq:/etc/rabbitmq/conf.d /home/environment/rabbitmq/config \
&& docker cp rabbitmq:/var/log/rabbitmq /home/environment/rabbitmq/log \
&& chmod -R 777 /home/environment/rabbitmq \
&& docker stop rabbitmq \
&& docker rm rabbitmq \
&& docker run \
-d \
--hostname myRabbitmq \
--name rabbitmq \
--restart=always \
-p 5672:5672 \
-p 15672:15672 \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=YuZhenAn123. \
-e RABBITMQ_DEFAULT_VHOST=rabbitmq_host \
-v /home/environment/rabbitmq/data:/var/lib/rabbitmq \
-v /home/environment/rabbitmq/log:/var/log/rabbitmq \
-v /home/environment/rabbitmq/config:/etc/rabbitmq/conf.d \
rabbitmq:3.12.1 \
&& docker exec -it rabbitmq rabbitmq-plugins enable rabbitmq_management \
&& echo "rabbitmq3.12.1 start!" \
&& mkdir -p /home/environment/nacos \
&& docker pull nacos/nacos-server:v2.2.3 \
&& docker run --name nacos -e MODE=standalone -p 8849:8848 -d nacos/nacos-server:v2.2.3 \
&& docker cp nacos:/home/nacos/logs/ /home/environment/nacos/ \
&& docker cp nacos:/home/nacos/conf/ /home/environment/nacos/ \
&& touch /home/environment/nacos/conf/createNacosConfig.sql \
&& chmod -R 777 /home/environment/nacos \
&& docker stop nacos \
&& docker rm nacos \
&& echo "CREATE DATABASE IF NOT EXISTS nacos_config;" >>/home/environment/nacos/conf/createNacosConfig.sql \
&& echo "use nacos_config;" >>/home/environment/nacos/conf/createNacosConfig.sql \
&& echo "source /home/mysql-schema.sql;" >>/home/environment/nacos/conf/createNacosConfig.sql \
&& docker cp /home/environment/nacos/conf/mysql-schema.sql mysql:/home \
&& docker cp /home/environment/nacos/conf/createNacosConfig.sql mysql:/home \
&& docker exec -it mysql mysql -uroot -pYuZhenAn123. -e "source /home/createNacosConfig.sql" \
&& sed -i '1s/^/MYSQL_SERVICE_PASSWORD=YuZhenAn123.\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/MYSQL_SERVICE_USER=root\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/MYSQL_SERVICE_DB_NAME=nacos_config\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/MYSQL_SERVICE_HOST=127.0.0.1\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/NACOS_AUTH_IDENTITY_KEY=serverIdentity\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/NACOS_AUTH_IDENTITY_VALUE=security\n/' /home/environment/nacos/conf/application.properties \
&& sed -i '1s/^/NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789\n/' /home/environment/nacos/conf/application.properties \
&& docker run -d \
--name nacos \
--restart=always \
-p 8848:8848  -p 9848:9848 -p 9849:9849 \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e NACOS_AUTH_ENABLE=true \
-e MODE=standalone \
-v /home/environment/nacos/logs:/home/nacos/logs \
-v /home/environment/nacos/conf:/home/nacos/conf \
nacos/nacos-server:v2.2.3 \
&& echo "nacos2.2.3 start!"